package com.ch.light.web.util;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

public abstract class UserContextUtil {

    public static Session getSession() {
        Subject currentSubject = SecurityUtils.getSubject();
        return currentSubject.getSession();
    }

    public static String getUserId() {
        return (String) getAttribute("userId");
    }

    public static String getAccount() {
        return (String) getAttribute("account");
    }

    public static String getCurrentRoleId() {
        return (String) getAttribute("roleId");
    }

    public static Object getAttribute(String key) {
        return getSession().getAttribute(key);
    }

    public static void setAttribute(String key, Object value) {
        getSession().setAttribute(key, value);
    }
}
